package org.spring.blog.utils;

import javax.servlet.http.HttpServletRequest;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 字符判断工具类
 */
public class TextUtil {

    private TextUtil() {
    }

    public static boolean isEmpty(String text) {
        return text == null || text.isEmpty();
    }

    public static boolean notEmpty(String text) {
        return !isEmpty(text);
    }


    public static boolean isEmailAddress(String _email) {
        Pattern pattern = Pattern.compile("^[A-Za-z\\d]+([-_.][A-Za-z\\d]+)*@([A-Za-z\\d]+[-.])+[A-Za-z\\d]{2,4}$");

        Matcher matcher = pattern.matcher(_email);

        return matcher.matches();
    }

    public static String getDomain(HttpServletRequest _request) {
        String servletPath = _request.getServletPath();
        StringBuffer requestURL = _request.getRequestURL();

        return requestURL.toString().replace(servletPath, "");
    }
}
